package com.hualan.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.domain.Free;
import com.hualan.mapper.FreeMapper;
import com.hualan.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FreeService {
    @Autowired
    private FreeMapper freeMapper;

    public R queryFreeList() {
        List<Free> list = freeMapper.queryFreeList();
        if (list == null) {
            return R.fail("查询失败!没有该数据！");
        }
        return R.success(list);
    }
    //查询所有
    public List<Free> selAllFree(){
        return freeMapper.selAllFree();
    }
    //分页
    public PageInfo<Free> selAllFreePage(int pageNum, int pageSize){
        int count = freeMapper.queyCountFree();
        PageHelper.startPage(pageNum,pageSize);
        List<Free> freeList=freeMapper.selAllFree();
        PageInfo<Free> pageInfo= new PageInfo<>(freeList);
        pageInfo.setTotal(count);
        return pageInfo;
    }

    //添加
    public int addFree(Free free){
        return freeMapper.insertSelective(free);

    }
    //按id删除
    public int delById(Long id){
        return freeMapper.deleteByPrimaryKey(id);
    }
    //模糊查询
    public List<Free> selLiskFree(String name){
        return freeMapper.selLikeFree(name);
    }

    //修改
    public int updateFree(Free free){
        return freeMapper.updateByPrimaryKeySelective(free);
    }

}
